博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jQuery Ajax File Upload(附源码)
阅读量:4459 次
发布时间:2019-06-08

本文共 1621 字,大约阅读时间需要 5 分钟。

项目结构

Default.aspx

Upload.aspx
Scripts/…
style.css

效果图

客户端html代码

隐藏行号 复制代码 Default.aspx
  1. <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="UploadFile.aspx.vb" Inherits="Web.UploadFile" %>
  2.  
  3.  
  4.  
  5.  
  6. $(function () {
  7. var btnUpload = $('#upload');
  8. var status = $('#status');
  9. new AjaxUpload(btnUpload, {
  10. action: 'Upload.aspx',
  11. //Name of the file input box
  12. name: 'uploadfile',
  13. onSubmit: function (file, ext) {
  14. if (!(ext && /^(jpg|png|jpeg|gif)$/.test(ext))) {
  15. // check for valid file extension
  16. status.text('Only JPG, PNG or GIF files are allowed');
  17. return false;
  18. }
  19. status.text('Uploading...');
  20. },
  21. onComplete: function (file, response) {
  22. //On completion clear the status
  23. status.text('');
  24. //Add uploaded file to list
  25. if (response === "success") {
  26. $('
  27. ').appendTo('#files').html('
    ' + file).addClass('success');
  28. } else {
  29. $('
  30. ').appendTo('#files').text(file).addClass('error');
  31. }
  32. }
  33. });
  34. });
  35.  
  36.  
  37.  
  38.  
  39. Upload File
  40.  
  41.  
  42. Upload File
    •  
    •  
    •  
    •  
    •  
    •  

    服务端处理代码Upload.aspx

    隐藏行号 复制代码 Default.aspx
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Web;
    5. using System.Web.UI;
    6. using System.Web.UI.WebControls;
    7.  
    8. namespace JqueryAjaxUploadTest
    9. {
    10. public partial class Upload : System.Web.UI.Page
    11. {
    12. protected void Page_Load(object sender, EventArgs e)
    13. {
    14. try
    15. {
    16. HttpPostedFile hpfFile = Request.Files["uploadfile"];
    17. hpfFile.SaveAs(Server.MapPath("~/uploads/") + hpfFile.FileName);
    18. Response.Write("success");
    19. }
    20. catch (Exception)
    21. {
    22.  
    23. Response.Write("fail");
    24. }
    25. }
    26. }
    27. }

    下载地址:

    找到文件 jquery ajax file upload(刚刚上传,文件可能还没刷出来)

    转载于:https://www.cnblogs.com/psunny/archive/2010/10/21/1857326.html

    你可能感兴趣的文章
    KeyProvider
    查看>>
    空指针为什么能调用成员函数?
    查看>>
    用MySQL的存储过程来实现一些经典函数
    查看>>
    React (2) -- State and Lifecycle
    查看>>
    【转】在EmEditor上编译并运行JAVA
    查看>>
    关于SqlDateTime溢出的问题
    查看>>
    jquery下php与ajax的数据交换方式
    查看>>
    魅蓝Note有几种颜色 魅蓝Note哪个颜色好看
    查看>>
    使用PullToRefresh实现下拉刷新和上拉加载
    查看>>
    透明度百分比与十六进制转换
    查看>>
    HBase表预分区
    查看>>
    NSBundle,UIImage,UIButton的使用
    查看>>
    vue-cli3 中console.log报错
    查看>>
    GridView 中Item项居中显示
    查看>>
    UML类图五种关系与代码的对应关系
    查看>>
    如何理解作用域
    查看>>
    从无到满意offer,你需要知道的那些事
    查看>>
    P1516 青蛙的约会 洛谷
    查看>>
    SDOI2011 染色
    查看>>
    JQuery EasyUI combobox动态添加option
    查看>>